'use strict';
/* Controllers */
app.controller('memberFramCtrl', ['$scope', '$http', '$state', 'apiService', '$cookieStore', '$timeout', '$stateParams', 'toaster', '$rootScope', 'ngDialog', function ($scope, $http, $state, apiService, $cookieStore, $timeout, $stateParams, toaster, $rootScope, ngDialog) {
    if (!$rootScope.framData) {
        $rootScope.framData = [];
    }

    apiService.post({
        modelName: 'member',
        apiName: 'getmemberdbDiyiDai'
    }, {
        previous: $stateParams.previous
    }, function (data) {
        if (data.code == 200) {
            if(data['data'].length==0){
                toaster.pop('error', '提示', '已经是最后一级啦！');
            }

            $rootScope.pageData = data['data'];
            $rootScope.framData.push(data['data']);
        } else {
            toaster.pop('error', '提示', data['msc']);
        }
    }, function (err) {
        toaster.pop('error', '提示', '服务器出小差咯...');
    });

    // 返回
    $scope.goBack = function () {
        history.back();
    }

    // 修改等级
    $scope.upUserLevel = function (item) {
        // 对话框
        $scope.dialog = {
            title: '提示',
            content: '选择用户等级?',
            previous: $rootScope.userObj['previous'],
            level: item.level
        };

        ngDialog.openConfirm({
            template: '/tpl/dialog.html',
            className: 'ngdialog-theme-plain',
            scope: $scope
        }).then(function (value) {
            if (value['statu'] == true) {
                if (value['val']) {
                    item['level'] = value['val'];
                }
                apiService.post({
                    modelName: 'member',
                    apiName: 'upmember'
                }, item, function (data) {
                    if (data.code == 200) {
                        toaster.pop('success', '提示', data['msc']);
                    } else {
                        toaster.pop('error', '提示', data['msc']);
                    }
                }, function (err) {
                    toaster.pop('error', '提示', '服务器出小差咯...');
                });
            }
        });

    }

    // 修改冻结状态
    $scope.upUserFreeze = function (item, freeze) {
        $scope.btn_disabled = true;
        item['freeze'] = freeze;
        apiService.post({
            modelName: 'member',
            apiName: 'upmember'
        }, item, function (data) {
            if (data.code == 200) {
                toaster.pop('success', '提示', data['msc']);
            } else {
                toaster.pop('error', '提示', data['msc']);
            }
            $scope.btn_disabled = false;
        }, function (err) {
            $scope.btn_disabled = false;
            toaster.pop('error', '提示', '服务器出小差咯...');
        });

    }

}]);